package com.wang.mandkey.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wang.mandkey.R;
import com.waps.AdInfo;

public class RecommandAdapter extends BaseAdapter {

	private Context mContext;

	private List<AdInfo> mArrAyList;

	public RecommandAdapter(Context context, List<AdInfo> adinfoList) {
		this.mContext = context;
		this.mArrAyList = adinfoList;
	}

	@Override
	public int getCount() {
		return mArrAyList.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder vl;
		if (null == convertView) {
			vl = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.item_recommand, null);

			vl.appImg = (ImageView) convertView.findViewById(R.id.imageAdIcon);
			vl.appScore = (TextView) convertView
					.findViewById(R.id.textViewScore);
			vl.appName = (TextView) convertView
					.findViewById(R.id.textViewAppName);
			vl.appDesc = (TextView) convertView
					.findViewById(R.id.textViewAdDesc);
			convertView.setTag(vl);
		} else {
			vl = (ViewHolder) convertView.getTag();
		}

		AdInfo adinfo = mArrAyList.get(position);
		vl.appImg.setImageBitmap(adinfo.getAdIcon());
		vl.appScore.setText("达人指数:" + adinfo.getAdPoints() + " 分");
		vl.appName.setText(adinfo.getAdName());
		vl.appDesc.setText(adinfo.getAdText());
		return convertView;
	}

	class ViewHolder {

		ImageView appImg;
		TextView appScore;
		TextView appName;
		TextView appDesc;

	}

}
